//
//  SettingViewController.m
//  PhotographyStudi
//
//  Created by 叶一枫 on 2017/5/17.
//  Copyright © 2017年 叶一枫. All rights reserved.
//

#import "SettingViewController.h"

@interface SettingViewController ()

@property(nonatomic,strong)NSArray *itemArr;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.itemArr = @[@"我的文件",@"安全设置",@"清除缓存",@"关于",@"意见反馈",@"注销"];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSArray *rowNum = @[@1,@1,@1,@3,@1];
    return [rowNum[section]integerValue];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        return 80;
    }
    return 44;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    if (section == 0) {
        return 20;
    }
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[BaseTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell" UIType:BASECELLSINGLE];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    switch (indexPath.section) {
        case 0:
        {
            SettingHeaderCell *cell = [[SettingHeaderCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"headerCell" UIType:BASECELLSINGLE];
            cell.nickName.text = @"BlackStar";
            cell.studiName.text = @"暗星摄影室_Cocobar";

            [cell.headerAvatar sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:IMAGE_NAMED(@"defaultAvatar")];
            cell.tapImage = ^{
                //查看头像
            };
            return cell;
        }
            break;
        case 1:
            cell.itemLabel.text = self.itemArr[indexPath.row];
            break;
        case 2:
            cell.itemLabel.text = self.itemArr[indexPath.row+1];
            break;
        case 3:
            cell.itemLabel.text = self.itemArr[indexPath.row+2];
            if (indexPath.row == 0) {
                NSInteger cacheSize = [[SDImageCache sharedImageCache] getSize];
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2f MB",cacheSize/(1024.0*1024.0)];
            }
            break;
        case 4:
            cell.itemLabel.text = self.itemArr[indexPath.row+5];
            break;
        default:
            break;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    if (indexPath.section == 0) {
        UserInfoTableViewController *userInfo = [self.storyboard instantiateViewControllerWithIdentifier:@"UserInfoTableViewController"];
        [self.navigationController pushViewController:userInfo animated:YES];
        
    }else if (indexPath.section == 1) {
        [self.navigationController pushViewController:[[BSTool sharedBSTool]getVCFromStoryboardWithID:@"FileManagerViewController"] animated:YES];
    }else if (indexPath.section == 2) {
        
    }else if (indexPath.section == 3) {
        switch (indexPath.row) {
            case 0:
                [[BSTool sharedBSTool]alertBaseWithTitle:@"清除缓存后将会重新加载已看过的图片数据" des:@"" complet:^(NSInteger index, id anyone) {
                    if (index == 1) {
                        [[SDImageCache sharedImageCache]clearDiskOnCompletion:^{
                        }];
                    }
                }];
                break;
            case 1:{
                [self.navigationController pushViewController:[[BSTool sharedBSTool]getVCFromStoryboardWithID:@"AboutUsViewController"] animated:YES];
            }
                break;
            case 2:
                
                break;
            default:
                break;
        }
        
        
    }else if (indexPath.section == 4) {
        [[BSTool sharedBSTool]alertBaseWithTitle:@"确定要注销吗?" des:@"" complet:^(NSInteger index, id anyone) {
            if (index == 1) {
                [[BSTool sharedBSTool]goRootVCFromtype:@"LOGIN"];
            }
        }];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
